/**
 * 详情对话框
 */
var DiscountInfoDlg = {
    data: {
        type: "",
        name: "",
        description: "",
        amountTotal: "",
        amountOut: "",
        amountPer: "",
        termDay: "",
        leastPrice: "",
        discountPrice: "",
        effectiveTime: "",
        expireTime: "",
        createTime: "",
        updateTime: "",
        recordStatus: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;

    //让当前iframe弹层高度适应
    //admin.iframeAuto();

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/discount/addItem", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });


        ajax.set(data.field);
        ajax.start();
    });

    laydate.render({
        elem: '#effectiveTime',
        type: 'datetime'

    });

    laydate.render({
        elem: '#expireTime',
        type: 'datetime'
    });
    form.verify({
        timeMin: function(value, item){ //value：表单的值、
            // item：表单的DOM对象
            if($("#expireTime").val()==""||$("#effectiveTime").val()==""){
                return '生效日期与有效日期不能为空';
            }else  if(Feng.datedifference($("#expireTime").val(),$("#effectiveTime").val())<=0 ){
                return '生效日期应小于过期日期';
            }
        }

        //我们既支持上述函数式的方式，也支持下述数组的形式
        //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
        ,pass: [
            /^[\S]{6,12}$/
            ,'密码必须6到12位，且不能出现空格'
        ]
    });


});